load("//bazel:mongo_src_rules.bzl", "idl_generator", "mongo_cc_library", "mongo_cc_unit_test")

package(default_visibility = ["//visibility:public"])

exports_files(
    glob([
        "*.h",
        "*.cpp",
    ]),
)

idl_generator(
    name = "ingress_request_rate_limiter_gen",
    src = "ingress_request_rate_limiter.idl",
    deps = [
        "//src/mongo/db:basic_types_gen",
    ],
)

mongo_cc_library(
    name = "ingress_request_rate_limiter",
    srcs = [
        "ingress_request_rate_limiter.cpp",
        ":ingress_request_rate_limiter_gen",
    ],
    deps = [
        ":rate_limiter",
        "//src/mongo:base",
        "//src/mongo/db:server_feature_flags",
        "//src/mongo/db:service_context",
        "//src/mongo/db/auth",
        "//src/mongo/rpc:client_metadata",
        "//src/mongo/transport:cidr_range_list_parameter",
    ],
)

idl_generator(
    name = "ingress_admission_control_gen",
    src = "ingress_admission_control.idl",
)

mongo_cc_library(
    name = "ingress_admission_control",
    srcs = [
        "ingress_admission_controller.cpp",
        ":ingress_admission_control_gen",
    ],
    hdrs = [
        "ingress_admission_controller.h",
    ],
    deps = [
        ":ingress_admission_context",
        ":rate_limiter",
        "//src/mongo:base",
        "//src/mongo/db:server_base",
        "//src/mongo/db:server_feature_flags",
        "//src/mongo/db:service_context",
        "//src/mongo/util/concurrency:ticketholder",
    ],
)

mongo_cc_library(
    name = "queues_server_status_section",
    srcs = [
        "queues_server_status_section.cpp",
    ],
    deps = [
        ":ingress_admission_control",
        ":ingress_request_rate_limiter",
        "//src/mongo/db:server_feature_flags",
        "//src/mongo/db:service_context",
        "//src/mongo/db/admission/execution_control:ticketing_system",
        "//src/mongo/db/commands/server_status:server_status_core",
        "//src/mongo/transport:transport_layer_common",
    ],
)

mongo_cc_library(
    name = "ingress_admission_context",
    srcs = [
        "ingress_admission_context.cpp",
    ],
    deps = [
        "//src/mongo/db:service_context",
        "//src/mongo/util/concurrency:admission_context",
    ],
)

mongo_cc_library(
    name = "rate_limiter",
    srcs = [
        "rate_limiter.cpp",
    ],
    deps = [
        "//src/mongo:base",
        "//src/mongo/db:server_base",
        "//src/mongo/db:service_context",
        "//src/third_party/folly:folly_token_bucket",
    ],
)

idl_generator(
    name = "flow_control_parameters_gen",
    src = "flow_control_parameters.idl",
)

mongo_cc_library(
    name = "flow_control_parameters",
    srcs = [
        ":flow_control_parameters_gen",
    ],
    deps = [
        "//src/mongo/db:server_base",
    ],
)

mongo_cc_library(
    name = "flow_control",
    srcs = [
        "flow_control.cpp",
    ],
    deps = [
        ":flow_control_parameters",
        "//src/mongo/db:server_base",
        "//src/mongo/db:service_context",
        "//src/mongo/db/commands/server_status:server_status_core",
        "//src/mongo/db/shard_role/lock_manager:flow_control_ticketholder",
        "//src/mongo/util:background_job",
    ],
)

mongo_cc_unit_test(
    name = "flow_control_test",
    srcs = [
        "flow_control_test.cpp",
    ],
    tags = ["mongo_unittest_fourth_group"],
    deps = [
        ":flow_control",
        "//src/mongo/db:service_context_d_test_fixture",
        "//src/mongo/db/repl:replmocks",
        "//src/mongo/unittest",
    ],
)

mongo_cc_unit_test(
    name = "ingress_admission_control_test",
    srcs = [
        "ingress_admission_control_test.cpp",
    ],
    tags = ["mongo_unittest_third_group"],
    deps = [
        ":ingress_admission_control",
        "//src/mongo/db:service_context_test_fixture",
        "//src/mongo/unittest",
    ],
)

mongo_cc_unit_test(
    name = "rate_limiter_util_test",
    srcs = [
        "rate_limiter_util_test.cpp",
    ],
    tags = [
        "mongo_unittest_second_group",
        "server-workload-resilience",
    ],
    deps = [
        ":rate_limiter",
        "//src/mongo/db:service_context_test_fixture",
    ],
)
